package com.suthund.bean.response;

import com.alibaba.fastjson.JSON;

/**
 * json
 * <p>
 * Created by yangkang on 2017/4/13.
 */
public class JsonResponse {

    private int state;

    private String errorCode;

    private String errorMsg;

    private JSON resultData;

    private JsonResponse(int state, String errorCode, String errorMsg, JSON resultData) {
        this.state = state;
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
        this.resultData = resultData;
    }

    public static JsonResponse R_200(String s) {
        return new JsonResponse(200, "", "", null);
    }

    public static JsonResponse R_200(JSON resultData) {
        JsonResponse jsonResponse;
        if (null == resultData) {
            jsonResponse = new JsonResponse(200, "", "", null);
        } else {
            jsonResponse = new JsonResponse(200, "", "", resultData);
        }
        return jsonResponse;
    }

    public static JsonResponse R_500(String errorCode, String errorMsg) {
        return new JsonResponse(500, errorCode, errorMsg, null);
    }

    public static JsonResponse R_100() {
        return new JsonResponse(100, "", "", null);
    }

    public static JsonResponse R_100(JSON resultData) {
        JsonResponse jsonResponse;
        if (null == resultData) {
            jsonResponse = new JsonResponse(100, "", "", null);
        } else {
            jsonResponse = new JsonResponse(100, "", "", resultData);
        }
        return jsonResponse;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public JSON getResultData() {
        return resultData;
    }

    public void setResultData(JSON resultData) {
        this.resultData = resultData;
    }

    @Override
    public String toString() {
        return "JsonResponse{" +
                "state=" + state +
                ", errorCode='" + errorCode + '\'' +
                ", errorMsg='" + errorMsg + '\'' +
                ", resultData= { " + resultData + " }" +
                '}';
    }
}
